//框架集成
function FrameOption(){
	//获取系统的参数
	this.getSrc=function(name){
		 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
		 var r = window.location.search.substr(1).match(reg);
		 if(r!=null)return  unescape(r[2]); return null;
	}
	//讓arttempalte從頁面消失
	this.artTemplateHide = function(){
		$('script[data-type=template]').each(function(){
			//easyBuy.global.template[$(this).attr('id')] = $(this).html().replace(/[\r\n]/g,"");
			$(this).remove();
		});
	}
	//给页面引入的js 全部加上?t=1923231214 
	this.sysEnTime = function(){
		 var scripts= document.getElementsByTagName("script");
		
		  for(var i=0;i<scripts.length;i++){
			  var scriptScr=scripts[i].getAttribute("src");
			  var NowDate=FrameOption.prototype.getNowFormatDate();
			  var newScriptsUrl=scriptScr;
			  if(scriptScr.indexOf("?") >= 0){
				  newScriptsUrl =scriptScr+"&t="+NowDate;
			  }else{
				  newScriptsUrl =scriptScr+"?t="+NowDate;
			  }
			/*  if(scriptScr.indexOf("http")<0){
				  newScriptsUrl=xurl+newScriptsUrl;
			  }*/
			  scripts[i].setAttribute("src",newScriptsUrl);
		  }
	}
	this.UUID=function (len, radix) { 
	    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); 
	    var uuid = [], i; 
	    radix = radix || chars.length; 
	    
	    if (len) { 
	      // Compact form 
	      for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix]; 
	    } else { 
	      // rfc4122, version 4 form 
	      var r; 
	    
	      // rfc4122 requires these characters 
	      uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; 
	      uuid[14] = '4'; 
	    
	      // Fill in random data.  At i==19 set the high bits of clock sequence as 
	      // per rfc4122, sec. 4.1.5 
	      for (i = 0; i < 36; i++) { 
	        if (!uuid[i]) { 
	          r = 0 | Math.random()*16; 
	          uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]; 
	        } 
	      } 
	    } 
	    return uuid.join(''); 
	}
	var salt1="";
	var salt2="";
	var salt3="";
	// DES加密 DES加密和解密过程中，密钥长度都必须是8的倍数
	this.encryptByDES = function(message){
		return strEnc(message,salt1,salt2,salt3);
	}
	//解密
	this.decryptByDES = function(ciphertext){
		return strDec(ciphertext,salt1,salt2,salt3);
	}
}

FrameOption.prototype={
	//属性集成
		addHref : function(href){
			var self = this;
			var hrefToken = self.systemAci(href);
			var param = "?_encryption=" + hrefToken;
			if(href.indexOf("?") >= 0) {
				param = "&_encryption=" + hrefToken;
			}
			param += "&_term=" + self.getNowFormatDate();
			return href + param;
		},
		systemAci : function(str){
			var self = this;
			str = self.replaceAtre(str);
			var strs = "";
			for(var i = 0; i < str.length; i++) {
				var ins = str[i];
				if(!isNaN(ins)) {
				} else {
					strs += ins.charCodeAt(ins);
				}
			}
			return strs;
		},
		replaceAtre : function(str){
			str = str.replace(/ /g, "");
			str = str.replace("?", "");
			str = str.replace(/&/g, "");
			return str;
		},
		getNowFormatDate : function(){
			var date = new Date();
			var seperator1 = "-";
			var seperator2 = ":";
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if(month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if(strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate + " " + date.getHours() + seperator2 + date.getMinutes() + seperator2 + date.getSeconds();
			var currentDateLong = new Date(currentdate.replace(new RegExp("-", "gm"),"/")).getTime();
			return currentDateLong;
		},
		getsec : function(str){
			var str1 = str.substring(1,str.length) * 1;
			var str2 = str.substring(0,1);
			if(str2 == 's'){
				return str1 * 1000;
			}else if(str == 'm'){
				return str1 * 60 * 1000;
			}else if(str2 == 'h'){
				return str1 * 60 * 60 * 1000;
			}else if(str2 == 'd'){
				return str1 * 24 * 60 * 60 * 1000;
			}
		}	
}
function Map(){
	this.values = new Array();
	this.put = function(key, val) {
		var data = {
			val : [ {
				keys : key,
				vals : val
			} ]
		};
		this.values[this.isKey(key)] = data;
	};
	this.get = function(key) {
		var len = this.isKey(key);
		var newValues = this.values[len];
		if (undefined != newValues) {
			newValues = newValues.val[0].vals;
			return newValues;
		} else {
			return "";
		}
	};
	this.isKey = function(key) {
		key = key + "";
		 key = FrameOption.prototype.replaceAtre(key); 
		key = key.toLowerCase();
		var len = key.length;
		var strs = 0;
		for ( var i = 0; i < len; i++) {
			var ins = key[i];
			if (!isNaN(ins)) {
				strs = parseInt(strs);
				ins = parseInt(ins);
				strs = ins * 2 + strs;
			} else {
				var int = ins.charCodeAt(ins);
				strs = parseInt(strs);
				strs = strs + int * 2;
			}
		}
		return strs;
	};
}

 // DES加密
function encryptByDES(message, key) {
    var keyHex = CryptoJS.enc.Utf8.parse(key);
    var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    });
    return encrypted.toString();
}
 //DES 解密
 function decryptByDES(ciphertext, key) {
        var keyHex = CryptoJS.enc.Utf8.parse(key);
        // direct decrypt ciphertext
        var decrypted = CryptoJS.DES.decrypt({
            ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
        }, keyHex, {
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return decrypted.toString(CryptoJS.enc.Utf8);
    }
//应用   
//var frame=new FrameOption();
 